

//
//  CPJRefreshControlView.swift
//  加载中
//
//  Created by YYY on 2017/8/22.
//  Copyright © 2017年 成品家（北京）网路科技有限公司. All rights reserved.
//

import UIKit

class CPJRefreshControlView: UIView {

    var parentHeight: CGFloat = 0
    
    //刷新状态
    var refreshState: CPJRefreshState = .Normal
    {
        didSet
        {
            switch refreshState
            {
            case .Normal:
                tipLabel?.text = "下拉刷新"
                //恢复箭头
                tipImageView?.isHidden = false
                //地址加载
                indicator?.stopAnimating()
            
                UIView.animate(withDuration: 0.33, animations: { 
                    self.tipImageView?.transform = CGAffineTransform.identity
                })
                
            case .Pulling:
                tipLabel?.text = "松开刷新"
                UIView.animate(withDuration: 0.33, animations: { 
                    let angle: CGFloat = .pi + 0.001
                    self.tipImageView?.transform = CGAffineTransform(rotationAngle: angle)
                })
                
            case .WillRefresh:
                tipLabel?.text = "加载中"
                //隐藏箭头
                tipImageView?.isHidden = true
                //开始旋转
                indicator?.startAnimating()
            }
        }
    }
    //指示器
    @IBOutlet weak var indicator: UIActivityIndicatorView?
    
    //提示图片
    @IBOutlet weak var tipImageView: UIImageView?

    //提示标签
    @IBOutlet weak var tipLabel: UILabel?

    //类方法
    class func refreshView() -> CPJRefreshControlView
    {
        let nib = UINib(nibName: "CPJMeituanRefreshControlView", bundle: nil)
        return nib.instantiate(withOwner: nil, options: nil)[0] as! CPJRefreshControlView
    }
}
